function [lpostd,likel,lpriord,lpriord_ss,flag_ok]=lmjPosterior(parest,parvec,parposest,funcmod,Y,trainvec,prpar,prss,solveopt,addsol,ssposest)
% ======================================================================
% LMJ_POSTMAX.M
% follow the structure of GENSYSPOST_VEC by Alejandro Justiniano (C)
% IN addition to putting priors on parameters, our current model put
% priors on steady state values.
% 
% AJ June 2010. Allow for mixed frequency if ADDSOL.FLAG_MIXFREQ==0 
% Solution depends on whether G is fixed or time varying, as in the case of
% a cummulator. Determined by ADDSOL.FLAG_GTV ==0 or GTV == 1 
% =======================================================================
lpostd=-1e15;
likel=-inf;
lpriord=-inf;
lpriord_ss=-inf; 
flag_ok=0;
%% Keep this always to ensure working with latest Value
parvec(parposest)=parest;
[likel,ssvec,flagLikelOK]=feval(addsol.funcLikel,parest,parvec,parposest,funcmod,Y,trainvec,solveopt,addsol);
%% Likelihood
if flagLikelOK~=1; return; end
%% Prior Density of Parameters
lpriord=sum(feval(@priordens,parvec, prpar.prior, prpar.alphap, prpar.betap, prpar.lbnd, prpar.ubnd));
if isinf(abs(lpriord))==1;return;end
%% Prior Density on Steady State
if ~isempty(ssposest)
    lpriord_ss = sum(feval(@priordens,ssvec(ssposest), prss.prior, prss.alphap, prss.betap, prss.lbnd, prss.ubnd));
    if isinf(abs(lpriord_ss))==1;return;end
else
    lpriord_ss=0;
end
%% log likelihood
lpostd = lpriord + lpriord_ss + likel;
%dispaj(lpostd); 
flag_ok=1;